<?php
/**
 * 提问回答历史列表
 * 提问历史、回答历史
 * 验证用户身份token
 * @author Edwin
 */

namespace V1\Controller;

use Common\Controller\ApiController;
use Think\Exception;

class QuizHistoryController extends ApiController
{
    public function rest()
    {
        switch ($this->_method) {
            case 'get': // get请求处理代码
                switch (I('get.type')) {
                    case 'ask_history':
                        $this->_getAsk();
                        break;
                    default:
                        $this->_getAnswer();
                        break;
                }
                break;
        }
    }

    /**
     * 获取历史提问列表
     */
    private function _getAsk()
    {
        $u_id = $this->userId;
        try {
            $request = D('Ask')->get_ask_history($u_id);
        } catch (Exception $exception) {
            $this->myApiPrint(C('STATUS')['101'], 400, []);
        }
        if (!$request) {
            $this->myApiPrint(C('STATUS')['230'], 201, []);
        } else {
            $this->myApiPrint(C('STATUS')['200'], 200, $request);
        }
    }

    /**
     * 获取历史回答列表
     */
    private function _getAnswer()
    {
        $u_id = $this->userId;
        try {
            $request = D('QuestionAnswer')->get_uid_by_answer_list($u_id);
        } catch (Exception $exception) {
            $this->myApiPrint(C('STATUS')['101'], 400, []);
        }
        if (!$request) {
            $this->myApiPrint(C('STATUS')['230'], 201, []);
        } else {
            $this->myApiPrint(C('STATUS')['200'], 200, $request);
        }
    }
}
